package com.pan.alg.leecode;

public class TreeMaxDepth {

 public class TreeNode {
   int val = 0;
   TreeNode left = null;
   TreeNode right = null;
 }

    /**
     *
     * @param root TreeNode类
     * @return int整型
     */
    public int maxDepth (TreeNode root) {
        // write code here

        int depth = calMaxDepth(root,0);

        return depth;
    }

    private int calMaxDepth(TreeNode root, int depth) {
        if(root==null){
            return 0;
        }
        int leftDepth=depth;
        int rightDepth=depth;
        if(root.left!=null){
            depth+=1;
            leftDepth = calMaxDepth(root.left,depth);
        }
        if(root.right!=null){
            depth+=1;
            rightDepth = calMaxDepth(root.right,depth);
        }

        return leftDepth>rightDepth?leftDepth:rightDepth;
    }




}
